package kr.pe.johnkim.chattingday.mobile.rest.dao;

import kr.pe.johnkim.chattingday.mobile.domain.ChattingDayMember;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import java.util.List;

/**
 * ChattingDay 사용자 관련 DAO 메소드들을 구현하는 클래스 이다.
 * 
 * @author : johnkim <cale9797@gmail.com / Bettersoft Inc,.>
 * @Date : 12. 5. 17
 */
public class ChattingDayMemberDaoImpl extends SqlMapClientDaoSupport implements ChattingDayMemberDao {

    // SLF4J Logging
    private Logger logger = LoggerFactory.getLogger(ChattingDayMemberDaoImpl.class);

    /**
     * 사용자 등록을 위해서 아이디 중복 검사를 한다.
     *
     * TotalCount 를 반환 한다.
     *
     * @param chattingDayMember
     * @return ChattingDayMember
     */

    @Override
    public ChattingDayMember checkIdDuplication(ChattingDayMember chattingDayMember) {
        logger.info("checkIdDuplication");
        
        return (ChattingDayMember)getSqlMapClientTemplate().queryForObject("CHATTINGDAY.checkIdDuplication", chattingDayMember);
    }

    /**
     * 사용자 등록을 위해서 메일 중복 검사를 한다.
     *
     * TotalCount 를 반환 한다.
     *
     * @param chattingDayMember
     * @return
     */
    @Override
    public ChattingDayMember checkMailDuplication(ChattingDayMember chattingDayMember) {
        logger.info("checkMailDuplication");

        return (ChattingDayMember)getSqlMapClientTemplate().queryForObject("CHATTINGDAY.checkMailDuplication", chattingDayMember);
    }

    /**
     * 사용자를 등록 한다.
     *
     * @param chattingDayMember
     * @return TRUE/FALSE
     */
    @Override
    public boolean registerMember(ChattingDayMember chattingDayMember) {
        logger.info("registerMember");

        boolean result;

        try {
            getSqlMapClientTemplate().insert("CHATTINGDAY_MEMBERS.registerMember", chattingDayMember);
            result = true;
        } catch (Exception e) {
            result = false;
        }

        return result;
    }

    /**
     * 사용자 정보를 가져 온다.
     *
     * @param chattingDayMember
     * @return ChattingDayMember
     */
    @Override
    public ChattingDayMember selectMemberInformation(ChattingDayMember chattingDayMember) {
        logger.info("selectMemberInformation");

        return (ChattingDayMember)getSqlMapClientTemplate().queryForObject("CHATTINGDAY_MEMBERS.selectMemberInformation", chattingDayMember);
    }

    /**
     * 사용자 로그인을 한다.
     *
     * @param chattingDayMember
     * @return
     */
    @Override
    public ChattingDayMember login(ChattingDayMember chattingDayMember) {
        logger.info("login");
        return (ChattingDayMember)getSqlMapClientTemplate().queryForObject("CHATTINGDAY_MEMBERS.login", chattingDayMember);
    }

    /**
     * 사용자 목록을 가져 온다.
     *
     * @param chattingDayMember
     * @return List<ChattingDayMember>
     */
    @Override
    public List<ChattingDayMember> selectMemberList(ChattingDayMember chattingDayMember) {
        logger.info("selectMemberList");
        
        return this.getSqlMapClientTemplate().queryForList("CHATTINGDAY_MEMBERS.selectMemberList", chattingDayMember);
    }

    /**
     * 사용자 정보를 수정 한다.
     *
     * @param chattingDayMember
     * @return TRUE/FALSE
     */
    @Override
    public boolean updateMemberInformation(ChattingDayMember chattingDayMember) {
        logger.info("updateMemberInformation");

        boolean result;

        try {
            getSqlMapClientTemplate().update("CHATTINGDAY_MEMBERS.updateMemberInformation", chattingDayMember);
            result = true;
        } catch (Exception e) {
            result = false;
        }

        return result;
    }

    /**
     * 사용자를 비활성화 한다.
     *
     * @param chattingDayMember
     * @return TRUE/FALSE
     */
    @Override
    public boolean updateDeactivateMember(ChattingDayMember chattingDayMember) {
        logger.info("updateDeactivateMember");

        boolean result;

        try {
            getSqlMapClientTemplate().update("CHATTINGDAY_MEMBERS.updateDeactivateMember", chattingDayMember);
            result = true;
        } catch (Exception e) {
            result = false;
        }

        return result;
    }

    /**
     * 사용자 마일리지를 가져 온다.
     *
     * @param chattingDayMember
     * @return
     */
    @Override
    public ChattingDayMember selectMileage(ChattingDayMember chattingDayMember) {
        logger.info("selectMileage");

        return (ChattingDayMember)getSqlMapClientTemplate().queryForObject("CHATTINGDAY_MEMBERS.selectMileage", chattingDayMember);
    }

    /**
     * 사용자 마일리지를 수정 한다.
     *
     * @param chattingDayMember
     * @return TRUE/FALSE
     */
    @Override
    public boolean updateMileage(ChattingDayMember chattingDayMember) {
        logger.info("updateMileage");

        boolean result;

        try {
            getSqlMapClientTemplate().update("CHATTINGDAY_MEMBERS.updateMileage", chattingDayMember);
            result = true;
        } catch (Exception e) {
            result = false;
        }

        return result;
    }

    /**
     * 사용자 벌점을 수정 한다.
     *
     * @param chattingDayMember
     * @return TRUE/FALSE
     */
    @Override
    public boolean updateRestrictionCount(ChattingDayMember chattingDayMember) {
        logger.info("updateRestrictionCount");

        boolean result;

        try {
            getSqlMapClientTemplate().update("CHATTINGDAY_MEMBERS.updateRestrictionCount", chattingDayMember);
            result = true;
        } catch (Exception e) {
            result = false;
        }

        return result;
    }

    /**
     * 사용자 사용제한 여부를 수정 한다.
     *
     * @param chattingDayMember (Y/N)
     * @return TRUE/FALSE
     */
    @Override
    public boolean updateRestrictionStatus(ChattingDayMember chattingDayMember) {
        logger.info("updateRestrictionStatus");

        boolean result;

        try {
            getSqlMapClientTemplate().update("CHATTINGDAY_MEMBERS.updateRestrictionStatus", chattingDayMember);
            result = true;
        } catch (Exception e) {
            result = false;
        }

        return result;
    }

    /**
     * 사용자 로그 상태를 업데이트 한다.
     *
     * @param chattingDayMember (IN/OUT)
     * @return TRUE/FALSE
     */
    @Override
    public boolean updateLogStatus(ChattingDayMember chattingDayMember) {
        logger.info("updateLogStatus");

        boolean result;

        try {
            getSqlMapClientTemplate().update("CHATTINGDAY_MEMBERS.updateLogStatus", chattingDayMember);
            result = true;
        } catch (Exception e) {
            result = false;
        }

        return result;
    }

    /**
     * 사용자 채팅방 참석 여부를 업데이트 한다.
     *
     * @param chattingDayMember (ON/OFF)
     * @return TRUE/FALSE
     */
    @Override
    public boolean updateChatStatus(ChattingDayMember chattingDayMember) {
        logger.info("updateChatStatus");

        boolean result;

        try {
            getSqlMapClientTemplate().update("CHATTINGDAY_MEMBERS.updateChatStatus", chattingDayMember);
            result = true;
        } catch (Exception e) {
            result = false;
        }

        return result;
    }

    /**
     * 사용자 Google GCM Registration Id 를 업데이트 한다.
     *
     * @param chattingDayMember
     * @return TRUE/FALSE
     */
    @Override
    public boolean updateRegistrationId(ChattingDayMember chattingDayMember) {
        logger.info("updateRegistrationId");

        boolean result;

        try {
            getSqlMapClientTemplate().update("CHATTINGDAY_MEMBERS.updateRegistrationId", chattingDayMember);
            result = true;
        } catch (Exception e) {
            result = false;
        }

        return result;
    }
}

